from manim import *
import numpy as np

'''
The Transform function maps points of the previous mobject to the points of the next mobject. 
This might result in strange behaviour, e.g. when the dots of one mobject are arranged clockwise 
and the other points are arranged counterclockwise. 
Here it might help to use the flip function and reposition the points 
via the roll function of numpy:     
'''
class RotationCompare(Scene):
    def construct(self):
        self.camera.background_color = WHITE

        # 左边正方形 -> 圆
        m1a = Square().set_color(RED).shift(LEFT)
        m1b = Circle().set_color(RED).shift(LEFT)

        # 右边正方形，不滚动点 -> 圆
        m2a = Square().set_color(BLUE).shift(RIGHT)
        m2b = Circle().set_color(BLUE).shift(RIGHT)

        # 右边正方形，滚动点
        m3a = Square().set_color(GREEN).shift(2*RIGHT)
        m3b = Circle().set_color(GREEN).shift(2*RIGHT)

        points = m3a.points
        points = np.roll(points, shift=int(len(points)/4), axis=0)
        m3a.points = points

        self.play(
            Transform(mobject=m1a, target_mobject=m1b),
            Transform(mobject=m2a, target_mobject=m2b),
            Transform(mobject=m3a, target_mobject=m3b),
            run_time=2
        )
